<script type="text/javascript"><!--//--><![CDATA[//><!--

    var LOVTenant = function(ao_option){
        try{
            if(ao_option==undefined){ ao_option={}; }
            var lf_onSelect = (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
            
            // Create Popup
            var $popup  = openPopup({ title:'Daftar Tenant' , width:700, height:370 });
            var ls_id   = $popup.attr('id');
            
            // Append Datagrid Container
            var ls_gridName = 'grid_'+ls_id;
            $popup  .html(  $('<div>')  .attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
                                        .html(  $('<div>').html($('<form>') .attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
                                                                            .html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
                                                                )
                                                )
                            )
                    .append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
            
            $('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
            $('#btn_search'+ls_id).linkbutton({  
                plain:true  
            }); 
            
            // Build Datagrid
            var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
            $('#'+ls_gridName).datagrid({  
                url:gs_path+'/pro_tenant/getdata/'+ls_param,
                queryParams: $('#fm_search_'+ls_id).serializeObject(),
                height:337,
                pagination:true,
                singleSelect:true,
                columns:[[
                    { field : 'no_tenant', title : 'No Tenant', width : 100, sortable:true },
                    { field : 'nama_tenant', title : 'Nama Tenant', width : 100, sortable:true },
                    { field : 'no_tenant', title : 'No Tenant', width : 300, sortable:true },
                    { field : 'jenis_usaha', title : 'Jenis Usaha', width : 300, sortable:true },
                    { field : 'id_lokasi', title : 'ID Lokasi', width : 100, sortable:true },
                    { field : 'lokasi_tempat', title : 'Lokasi Tempat', width : 300, sortable:true },
                    { field : 'harga_sewa', title : 'Harga Sewa', width : 300, sortable:true },
                ]],
                onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
            });
            
        } catch (err) { alert('Func. LOVSampleReference :\n' + err); }
    };

 	$(document).ready(function() {
		// Setup Form
		$('#form_master').setupForm([
			{ name: 'no_tagihan_sewa', type: 'text', size: 'short', maxlength: 10, readonly:true},
			{ name: 'nama_tenant', type: 'lov', size: 'long',
				onClearButton:function(){
					$(this).setval(''); 
					$('#nama_tenant').setval(''); 
					$('#no_toko').setval('');
					$('#jenis_usaha').setval('');
					$('#lokasi_tempat').setval('');
					$('#harga_sewa').setval('');
				},
				onActionButton:function(){ 
					LOVTenant({ onSelect:function(row){
                        $('#no_tenant').setval(row.no_tenant);
						$('#nama_tenant').setval(row.nama_tenant); 
						$('#no_toko').setval(row.no_toko);
                        $('#id_lokasi').setval(row.id_lokasi);
						$('#jenis_usaha').setval(row.jenis_usaha);
						$('#lokasi_tempat').setval(row.lokasi_tempat); 
						$('#harga_sewa').setval(row.harga_sewa); 
					} }); 
				}
			},
			{ name: 'no_toko', type: 'text', size: 'short', maxlength: 10, readonly:true},
			{ name: 'jenis_usaha', type: 'text', size: 'long', maxlength: 100, readonly:true},
			{ name: 'lokasi_tempat', type: 'text', size: 'medium', maxlength: 50, readonly:true},
			{ name: 'harga_sewa', type: 'text', size: 'medium', maxlength: 50, readonly:true},
			{ name: 'bulan', type: 'text', size: 'medium', maxlength: 10},
            { name: 'set_bulan_dari', type: 'text', size: 'short', maxlength: 10},
            { name: 'set_bulan_sampai', type: 'text', size: 'short', maxlength: 10},
            { name: 'set_tahun_dari', type: 'text', size: 'short', maxlength: 10},
            { name: 'set_tahun_sampai', type: 'text', size: 'short', maxlength: 10},
            { name: 'set_status_bayar', type: 'text', size: 'medium', maxlength: 10},
			{ name: 'tahun', type: 'text', size: 'medium', maxlength: 10},
			{ name: 'status_bayar', type: 'text', size: 'medium', maxlength: 50},
            { name: 'tanggal_bayar', type: 'date', size: 'short', maxlength: 15},
            { name: 'no_bukti_pembayaran', type: 'text', size: 'medium', maxlength: 25}
		], <?php echo json_encode($data); ?>);
        
		 <?php if (isset($no_tagihan_sewa)) {
        		?>
        		var no_tagihan_sewa = "<?php echo $no_tagihan_sewa; ?>";
        		<?php
        	}
        ?>

      /*  $('#bulan').change(function() {
             $('#id_bulan').setval($('#bulan').val());
        });*/

        $("#normal-1").show();
        $("#normal-2").show();
        $("#rapel-1").hide();
        $("#rapel-2").hide();

        <?php if($mode=="create"){ ?>
        $('#no_tagihan_sewa').readonly();
        $('#id_tagihan_sewa').setval('<?php echo $id_tagihan_sewa_auto; ?>');
        <?php } ?>

        <?php if($mode=="edit"){ ?>
        $('#no_tagihan_sewa').readonly();
        var no_tagihan_sewa = '<?php echo $no_tagihan_sewa ; ?>'
        $('#id_tagihan_sewa').setval('<?php echo $id_tagihan_sewa_edit; ?>');
        $('#id_lokasi').setval('<?php echo $id_lokasi_edit; ?>');
        $('#no_tenant').setval('<?php echo $no_tenant_edit; ?>');
        //alert( $('#id_lokasi').val());
            var bulan = '<?php echo $bulan ; ?>'
            var tahun = '<?php echo $tahun ; ?>'

            $('#bulan').setval(bulan);
            $('#tahun').setval(tahun);

        // Set Action Button
          var buttons = [{ label: 'Edit Status Bayar', icon: 'edit', onclick: function() { 
                          /* loadPage(gs_path + '/'+controller+'/edit_status/?no_tagihan_sewa=/'+no_tagihan_sewa)*/;
                            $("#normal-1").hide();
                            $("#normal-2").hide();
                            $("#rapel-1").show();
                            $("#rapel-2").show();
                            $("#mode_status").setval(1);
                        }},
                        { label: 'Save', icon: 'save', onclick: function() {
                            $('#form_master').submitForm(   '/'+controller+'/ajax_post'  ); 
                        }},
                       { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
        setAction(buttons);

        <?php } else { ?>
		
		// Set Action Button
		  var buttons = [
                        { label: 'Save', icon: 'save', onclick: function() { 
                            $('#form_master').submitForm(   '/'+controller+'/ajax_post'  ); 
                        }},
                       { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
        setAction(buttons);

        <?php } ?>

		<?php if (isset($no_tagihan_sewa)) {
        		?>
		$('#no_tagihan_sewa').setval(no_tagihan_sewa);
        		<?php
        	}
        ?>
		
		// Create Tab
		$('#tt').tabs({ border:false });  
		
		// Focus at First Object
		$('#form_master').focusFirst();

		
    });




//--><!]]></script>

<div id="form_master_message" style="display:none;"></div>
    <table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <input id="id_tagihan_sewa" name="id_tagihan_sewa" type="hidden"/>
            <input id="id_bulan" name="id_bulan" type="hidden"/>
            <input id="id_lokasi" name="id_lokasi" type="hidden"/>
            <input id="no_tenant" name="no_tenant" type="hidden"/>
        </td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Tagihan Sewa</td>
        <td><input id="no_tagihan_sewa" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tanggal Pembayaran</td>
        <td><input id="tanggal_bayar" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Bukti Pembayaran</td>
        <td><input id="no_bukti_pembayaran" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Tenant</td>
        <td ><input id="nama_tenant"/></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Toko</td>
        <td ><input id="no_toko" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Jenis Usaha</td>
        <td ><input id="jenis_usaha" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Lokasi Tempat</td>
        <td ><input id="lokasi_tempat" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Harga Sewa</td>
        <td ><input id="harga_sewa" /></td>
    </tr>
    <tr id="normal-1">
        <td class="label" style="width:150px">Periode Tagihan</td>
        <td ><select id="bulan" name="bulan">
            <option value="01">Januari</option>
            <option value="02">Februari</option>
            <option value="03">Maret</option>
            <option value="04">April</o ption>
                <option value="05">Mei</option>
                <option value="06">Juni</option>
                <option value="07">Juli</option>
                <option value="08">Agustus</option>
                <option value="09">September</option>
                <option value="10">Oktober</option>
                <option value="11">November</option>
                <option value="12">Desember</option>
            </select>
            <?php
            $now = date('Y');
            $pastYear = $now - 10; 
            echo "<select id='tahun' name='tahun' >";
            for ($a=$pastYear;$a<=$now;$a++)
            {
               echo"<option value='".$a."''>".$a."</option>";	
           }
           echo"</select>";
           ?>
       </td>
   </tr>
   <tr id="normal-2">
       <td class="label" style="width:150px">Status Bayar</td>
       <td ><select id="status_bayar" name="status_bayar">
          <option value="Belum Bayar">Belum Bayar</option>
          <option value="Sudah Bayar">Sudah Bayar</option>
      </select></td>
  </tr>
       <tr id="rapel-1">
        <td  class="label" style="width:150px">Periode Tagihan</td>
        <td ><select id="set_bulan_dari" name="set_bulan_dari">
            <option value="01">Januari</option>
            <option value="02">Februari</option>
            <option value="03">Maret</option>
            <option value="04">April</o ption>
                <option value="05">Mei</option>
                <option value="06">Juni</option>
                <option value="07">Juli</option>
                <option value="08">Agustus</option>
                <option value="09">September</option>
                <option value="10">Oktober</option>
                <option value="11">November</option>
                <option value="12">Desember</option>
            </select><?php
            $now = date('Y');
            $pastYear = $now - 10; 
            echo "<select id='set_tahun_dari' name='set_tahun_dari' >";
            for ($a=$pastYear;$a<=$now;$a++)
            {
                echo"<option value='".$a."''>".$a."</option>";  
            }
            echo"</select>";
            ?>
            S/D<select id="set_bulan_sampai" name="set_bulan_sampai">
            <option value="01">Januari</option>
            <option value="02">Februari</option>
            <option value="03">Maret</option>
            <option value="04">April</o ption>
                <option value="05">Mei</option>
                <option value="06">Juni</option>
                <option value="07">Juli</option>
                <option value="08">Agustus</option>
                <option value="09">September</option>
                <option value="10">Oktober</option>
                <option value="11">November</option>
                <option value="12">Desember</option>
            </select>
            <?php
            $now = date('Y');
            $pastYear = $now - 10; 
            echo "<select id='set_tahun_sampai' name='set_tahun_sampai' >";
            for ($a=$pastYear;$a<=$now;$a++)
            {
                echo"<option value='".$a."''>".$a."</option>";  
            }
            echo"</select>";
            ?>
        </td>
    </tr>
    <tr id="rapel-2"><td class="label" style="width:150px">Status Bayar</td>
        <td ><select id="set_status_bayar" name="set_status_bayar">
            <option value="Belum Bayar">Belum Bayar</option>
            <option value="Sudah Bayar">Sudah Bayar</option>
        </select>
    </td>
</tr>
<tr>
     <td><input id="mode_status" name="mode_status" type="hidden"/></td>
</tr>
</tr>
</table>
